package com.huadao.cart_ccs.data.task;

import com.huadao.cart_ccs.common.RockToast;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.Operation;

import java.util.Date;

public abstract class OperateTask {
    //正在进行的任务
    protected byte task;

    protected int state = STATE_UNSTART;
    public final static int STATE_UNSTART = 0;
    public final static int STATE_STARTING = 1;
    public final static int STATE_STARTED = 2;
    public final static int STATE_PAUSEING = 3;
    public final static int STATE_PAUSE = 4;
    public final static int STATE_RESUMEING = 5;
    public final static int STATE_RESUMED = 6;
    public final static int STATE_ENDING = 7;
    public final static int STATE_END = 8;

    protected Date startTime;
    protected Date pauseTime;
    protected Date endTime;

//    protected Operation operation;

    //在当前项目中的总运行时间
    protected long totalRunTime;

    private int speed;

    //操作时间
    private Date operateDate;
    private String operator;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getPauseTime() {
        return pauseTime;
    }

    public void setPauseTime(Date pauseTime) {
        this.pauseTime = pauseTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean isDuringTask() {
        if (state == STATE_UNSTART) {
            return false;
        } else if (state == STATE_END) {
            return false;
        } else {
            return true;
        }
    }

    //是否在运行
    public boolean isRunned() {
//        if(state==STATE_UNSTART||state==STATE_PAUSE||state==STATE_END){
//            return false;
//        }else if(state==STATE_STARTED||state==STATE_RESUMED){
//            return true;
//        }else {
//
//        }
        if (state == STATE_STARTED || state == STATE_RESUMED) {
            return true;
        } else {
            return false;
        }
    }

    //是否停止
    public boolean isStoped() {
//        if(state==STATE_UNSTART||state==STATE_PAUSE||state==STATE_END){
//            return false;
//        }else if(state==STATE_STARTED||state==STATE_RESUMED){
//            return true;
//        }else {
//
//        }
        if (state == STATE_UNSTART || state == STATE_PAUSE || state == STATE_END) {
            return true;
        } else {
            return false;
        }
    }

    public void ingToEd() {
        if (state == STATE_STARTING) {
            state = STATE_STARTED;
            setStartTime(new Date());
        } else if (state == STATE_ENDING) {
            state = STATE_END;
            setEndTime(new Date());
        } else if (state == STATE_PAUSEING) {
            state = STATE_PAUSE;
            setPauseTime(new Date());
        } else if (state == STATE_RESUMEING) {
            state = STATE_RESUMED;
            setStartTime(new Date());
        }
    }

    public Date getOperateDate() {
        return operateDate;
    }

    public void setOperateDate(Date operateDate) {
        this.operateDate = operateDate;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }
}
